package com.recipedb.recipedb.controller;

import com.recipedb.recipedb.entity.Category;
import com.recipedb.recipedb.entity.Ingredient;
import com.recipedb.recipedb.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/category")
public class CategoryController {

    @Autowired
    private CategoryService service;

    @PostMapping
    public Category add(@RequestBody Category entity) {
        return service.save(entity);
    }

    @DeleteMapping
    public void delete(@RequestParam Long id) {
        service.deleteById(id);
    }

    @GetMapping("/single")
    public Optional<Category> get(@RequestParam Long id) {
        return service.findById(id);
    }

    @GetMapping("/all")
    public List<Category> getAll() {
        return service.findAll();
    }

    @GetMapping("/by-recipe")
    public List<Category> getByRecipeId(@RequestParam Long recipeId) {
        return service.findByRecipeId(recipeId);
    }
}
